//PAT 1158
#include <bits/stdc++.h>
using namespace std;
class TeleUFS{
public:
    using pii=pair<int,int>;
    TeleUFS();
    void Findsuspect();
    int UFS_Find(int v);
    void UFS_Union(int a,int b);
    void solve();
private:
    int K;
    int N;
    int M;
    vector<vector<int>> teleGraph;//Mark the information of telephone time.
    vector<int> Telefraud;
    vector<int> UFS;
    vector<vector<int>> gang;
};
TeleUFS::TeleUFS(){
    cin>>K>>N>>M;
    teleGraph.resize(N+1);
    UFS.resize(N+1);
    for(int i=1;i<=N;i++){
        teleGraph[i].resize(N+1);
        UFS[i]=i;
    }
    for(int i=0;i<M;i++){
        int a,b,d;
        cin>>a>>b>>d;
        teleGraph[a][b]=teleGraph[a][b]+d;
    }
    gang.resize(N+1);
}
void TeleUFS::Findsuspect(){
    for(int i=1;i<=N;i++){
        int send=0;
        int back=0;
        for(int j=1;j<=N;j++){
            if(i!=j){
                if(teleGraph[i][j]!=0&&teleGraph[i][j]<=5){
                    send++;
                    if(teleGraph[j][i]!=0){
                        back++;
                    }
                }
            }
        }
        if(send>K&&back*5<=send){
            Telefraud.push_back(i);
        }
    }
}
int TeleUFS::UFS_Find(int v){
    if(UFS[v]==v){
        return v;
    }else{
        int a=UFS_Find(UFS[v]);
        UFS[v]=a;
        return a;
    }
}
void TeleUFS::UFS_Union(int a,int b){
	int faA = UFS_Find(a);
	int faB = UFS_Find(b);

	int min_ = min(faA, faB);
	int max_ = max(faA, faB);
	UFS[max_] = min_;
}
void TeleUFS::solve(){
    Findsuspect();
    if(Telefraud.size()==0){
        cout<<"None"<<endl;
        return;
    }
    for(int i=0;i<Telefraud.size();i++){
        for(int j=i+1;j<Telefraud.size();j++){
            if(teleGraph[Telefraud[i]][Telefraud[j]]!=0&&teleGraph[Telefraud[j]][Telefraud[i]]!=0){
                UFS_Union(Telefraud[i],Telefraud[j]);
            }
        }
    }
    for(int i=0;i<Telefraud.size();i++){
        gang[UFS[Telefraud[i]]].push_back(Telefraud[i]);
    }
    for(int i=0;i<gang.size();i++){
		if(gang[i].size()!=0){
			sort(gang[i].begin(), gang[i].end());
			for (int j = 0;j<gang[i].size();j++) {
				if (j == 0)cout << gang[i][j];
				else cout << " " << gang[i][j];
			}
			cout << endl;
		}
	}
    return;
}
int main(){
    TeleUFS ufs;
    ufs.solve();
}